# -*- coding: utf-8 -*-

import sys
import os
import os.path
import ConfigParser
import imp


# ---------- Get exe path. solved the problem of py2exe ---------- #
def main_is_frozen():
	return (hasattr(sys, "frozen") or # new py2exe
			hasattr(sys, "importers") # old py2exe
			or imp.is_frozen("__main__")) # tools/freeze


def get_main_dir():
	if main_is_frozen() and sys.platform != 'darwin':
		return os.path.abspath(os.path.dirname(sys.executable))
	return os.path.abspath(os.path.dirname(sys.argv[0]))


def getIconPath(iconName):
	iconExt = 'ico'
	if sys.platform == 'darwin':
		iconExt = 'icns'
	iconPath = (os.path.abspath(os.path.dirname(get_main_dir()))
					  + os.sep + 'rsc'+ os.sep + iconName + '.' + iconExt )#local
	if not os.path.isfile(iconPath):
		iconPath = os.path.join(os.path.abspath(get_main_dir()),
									   iconName + '.exe')#py2exe
		if sys.platform == 'darwin':
			iconPath = os.path.join(os.path.abspath(get_main_dir()),
									   iconName + '.icns')#py2app
	return iconPath


def getResPath(fileName):
	filePath = (os.path.abspath(os.path.dirname(get_main_dir()))
					  + os.sep + 'rsc'+ os.sep + fileName)#local
	if not os.path.isfile(filePath):
		filePath = os.path.join(os.path.abspath(get_main_dir()),
									   fileName)#py2exe
	return filePath

# ---------- Log ---------- #
LOGFILE = 'Mayapad.log'
LOGFILE_PATH = (os.path.abspath(get_main_dir())
				  + os.sep + 'src'+ os.sep + LOGFILE)#local
if not os.path.isfile(LOGFILE_PATH):
	LOGFILE_PATH = os.path.join(os.path.abspath(get_main_dir()),
								   LOGFILE)#py2exe
